/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sunsite.dao;

import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import sunsite.po.Resume;

/**
 *
 * @author mg
 */
public class ResumeDaoImpl extends HibernateDaoSupport implements ResumeDao {

    public void addResume(Resume resume) {
        this.getHibernateTemplate().save(resume);
    }

    public Resume getResumeByUsr(final String id) {
        List<Resume> list = getHibernateTemplate().executeFind(new HibernateCallback() {

            public Object doInHibernate(Session arg0) throws HibernateException, SQLException {
                return arg0.createQuery("from Resume as r where r.usr.userId = ?").setParameter(0, id).setMaxResults(1).list();
            }
        });
        if(list!=null&&list.size()>0)
            return list.get(0);
        else
            return null;
    }

    public void updateResume(Resume resume) {
        this.getHibernateTemplate().update(resume);
    }

    public void deleteResume(Resume resume) {
        this.getHibernateTemplate().delete(resume);
    }

}
